#include "stdafx.h"
#include "MeanShiftTracker.h"
#include "trackingobjects.h"
#include "hm.h"

#pragma once
namespace cvLib
{
	public ref class OurMethod
	{		
	public:					
		
		IplImage*						img;

		// Tracker
		MeanShiftTracker*				msTrackPtr;
		TrackingObjects*				trackObjPtr; 
		TrackingObjects**				trackSet;
		static const int				objectNum = MaxNumPeople;		
		static const char*				winName = "Tracking";
		CvRect**						objectLocations;
		
		arma::Col<eT>*					dataLocXPtr;
		arma::Col<eT>*					dataLocYPtr;
		arma::Col<eT>*					dataLocOriPtr;		
		int								szCurPeopleOM;

		// Calibration
		struct camera_parameters*		caliParaPtr;
		struct calibration_constants*	caliConstPtr;

		// HeatMap
		HM*								hm;

		OurMethod()
		{
			img =  cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 3);
			msTrackPtr = new MeanShiftTracker();

			trackObjPtr = new TrackingObjects();
			trackSet = new TrackingObjects*[objectNum];
			for (int i = 0;i < objectNum;i++)
			{
				trackSet[i] =  new TrackingObjects();
			}

			objectLocations = new CvRect*[objectNum];	
			for (int i = 0;i < objectNum;i++)
			{
				objectLocations[i] =  new CvRect();
			}

			dataLocXPtr = new arma::Col<eT>(objectNum);
			dataLocYPtr = new arma::Col<eT>(objectNum);
			dataLocOriPtr= new arma::Col<eT>(objectNum);

			szCurPeopleOM = 0;

			caliParaPtr = new struct camera_parameters;
			caliConstPtr = new struct calibration_constants;

			hm = new HM();

			cvNamedWindow(winName, CV_WINDOW_AUTOSIZE );
			//initTracker();
		};
		~OurMethod()
		{
			delete img;
			delete msTrackPtr;

			delete trackObjPtr;
			for (int i = 0;i < objectNum;i++)
			{
				delete trackSet[i];  
			}
			delete []trackSet;

			for (int i = 0;i < objectNum;i++)
			{
				delete objectLocations[i];  
			}
			delete []objectLocations;

			delete hm;
		}
		void createWindows();
		bool getImagefromCS(array<unsigned char>^ a, int nSize);
		void methodRun(array<unsigned char>^ pData, int nSize);
		void initTracker();
		void methodRunLocal();
		
	};
	void on_mouse(int event, int x, int y, int flags, void* param)
	{
		int ly = 1;
		MeanShiftTracker* pObj = static_cast<MeanShiftTracker*>(param);
		pObj->handleMouseEvents(event,x,y,flags,param);		
	}
}